package com.sam.core.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @project EMan
 * @author Sam
 * @version
 * @date Mar 10, 2009 3:17:58 PM
 */
public class PropertiesUtil {
	private static Logger log = LoggerFactory.getLogger(PropertiesUtil.class);

	public static Properties getProperties(String path) {

		InputStream in = PropertiesUtil.class.getResourceAsStream(path);
		Properties varp = new Properties();
		try {
			varp.load(in);
		} catch (IOException e) {
			log.error("读取database.properties错误", e);
		}
		return varp;

	}

	public static Properties getConfigProperties() {

		InputStream in = PropertiesUtil.class
				.getResourceAsStream("/com/eman/util/codeGen/conf.properties");
		Properties varp = new Properties();
		try {
			varp.load(in);
		} catch (IOException e) {
			log.error("读取database.properties错误", e);
		}
		return varp;

	}

	public static Properties getDatebaseProperties() {

		InputStream in = PropertiesUtil.class.getResourceAsStream("/database.properties");
		Properties varp = new Properties();
		try {
			varp.load(in);
		} catch (IOException e) {
			log.error("读取database.properties错误", e);
		}
		return varp;

	}

	public static String getProperty(Properties varp, String name, String encode) {
		try {
			return new String(varp.getProperty(name).getBytes("UTF-8"), encode);
		} catch (UnsupportedEncodingException e) {
			log.error("读取database.properties错误", e);
			return null;
		}
	}

}
